﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using appServices;

namespace appServices
{
    class Example
    {
        public Example()
        {
            // INSTANCE DE MA CLASSE DE CONNEXION AVEC SINGLETON SVP
            Database db = Database.getInstance();

            ////////////////////////////////////////////////////////////////////

            // SELECT ALL
            List<Object> selectAllClients = db.check(db.getModel().CLIENT.Select(cli => cli));

            foreach (CLIENT cli in selectAllClients)
            {
                Console.WriteLine(cli.CLIENTLASTNAME);
            }

            ////////////////////////////////////////////////////////////////////

            // SELECT WITH WHERE
            List<Object> selectClient = db.check(db.getModel().CLIENT.
                Where(cli => cli.CLIENTCOUNTRY == "France"));

            foreach (CLIENT cli in selectClient)
            {
                Console.WriteLine(cli.CLIENTLASTNAME);
            }

            ////////////////////////////////////////////////////////////////////

            // SELECT WITH WHERE
            CATALOG selectCatalog = (CATALOG)db.check(db.getModel().CATALOG.
                First(cat => cat.CATALOGID == 3));

            foreach (PRODUCT product in selectCatalog.PRODUCT)
            {
                Console.WriteLine(product.PRODUCTNAME);
            }

            ////////////////////////////////////////////////////////////////////

            // UPDATE
            CLIENT UserAModifier = (CLIENT)db.check(db.getModel().CLIENT.
                First(cli => cli.CLIENTID == 1));

            UserAModifier.CLIENTLASTNAME = "Sengel";
            //db.getModel().SaveChanges();

            ////////////////////////////////////////////////////////////////////

            // INSERT NEW CLIENT
            db.getModel().AddToCLIENT(new CLIENT()
            {
                CLIENTLASTNAME = "Takeda",
                CLIENTFIRSTNAME = "Shingen",
                CLIENTPASSWORD = "shoguntotalwar"
            });

            ////////////////////////////////////////////////////////////////////

            // COMMIT AFTER INSERT OR UPDATE
            //db.getModel().SaveChanges();

            ////////////////////////////////////////////////////////////////////

            Console.Read();
        }
    }
}